package fr.LesLoutresSauvages.laloutresportive.util;

import org.json.JSONException;
import org.json.JSONObject;

public class Departement implements JsonConvertible
{

  private int id;
  private String nom;
  private String code;

  
  
  
  
  public Departement()
  {
    super();
    this.id = 0;
    this.nom = "";
    this.code = "";
  }

  public Departement(int id, String nom, String code)
  {
    super();
    this.id = id;
    this.nom = nom;
    this.code = code;
  }

  
  
  
  
  
  public int getId()
  {
    return id;
  }

  public void setId(int id)
  {
    this.id = id;
  }

  public String getNom()
  {
    return nom;
  }

  public void setNom(String nom)
  {
    this.nom = nom;
  }

  public String getCode()
  {
    return code;
  }

  public void setCode(String code)
  {
    this.code = code;
  }

  
  
  
  
  @Override
  public String toString()
  {
    return "Departement [id=" + id + ", nom=" + nom + ", code=" + code + "]";
  }

  
  
  
  
  @Override
  public String toJSON()
  {
    JSONObject jObj = new JSONObject();
    try
    {
      jObj.put("id", this.getId());
      jObj.put("nom", this.getNom());
      jObj.put("code", this.getCode());
    }
    catch (JSONException e)
    {
      e.printStackTrace();
    }
    
    return ( jObj.toString() );
  }

  @Override
  public void fromJSON(String str)
  {
    try
    {
      JSONObject jObj = new JSONObject(str);
      this.setId(jObj.getInt("id"));
      this.setNom(jObj.getString("nom"));
      this.setCode(jObj.getString("code"));
    }
    catch (JSONException e)
    {
      e.printStackTrace();
    }
  }
}
